local skel = fk.CreateSkill {
  name = "emo__xiuyu",
  max_phase_use_time = 1,
}

Fk:loadTranslationTable{
  ["emo__xiuyu"] = "朽域",
  [":emo__xiuyu"] = "出牌阶段限一次，你可以令至多三名角色各视为使用一张【树上开花】，并将其弃置的黑色牌置于其武将牌上。",

  ["#emo__xiuyu"] = "朽域:令至多三名角色各视为使用一张【树上开花】，弃置的黑色牌置于其武将牌上",
}

skel:addEffect("active", {
  anim_type = "support",
  prompt = "#emo__xiuyu",
  card_num = 0,
  min_target_num = 1,
  max_target_num = 3,
  target_filter = function (self, player, to_select, selected)
    return #selected < 3 --and not to_select:isNude()
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local tos = effect.tos
    room:sortByAction(tos)
    for _, to in ipairs(tos) do
      if not to:isNude() and not to.dead then
        room:useVirtualCard("bogus_flower", nil, to, to, skel.name)
      end
    end
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player.dead then return false end
    local parent = player.room.logic:getCurrentEvent().parent
    if parent and parent.event == GameEvent.SkillEffect then
      parent = parent.parent
      if parent and parent.event == GameEvent.CardEffect then
        local eff = parent.data
        if eff.card.name == "bogus_flower" and table.contains(eff.card.skillNames, skel.name) then
          local ids = {}
          for _, move in ipairs(data) do
            if move.from == player and move.moveReason == fk.ReasonDiscard
             and move.skillName and string.find(move.skillName, "bogus_flower") then
              for _, info in ipairs(move.moveInfo) do
                if player.room:getCardArea(info.cardId) == Card.DiscardPile and Fk:getCardById(info.cardId).color == Card.Black then
                  table.insert(ids, info.cardId)
                end
              end
            end
          end
          if #ids > 0 then
            event:setCostData(self, {cards = ids})
            return true
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:addToPile(skel.name, event:getCostData(self).cards, true, skel.name)
  end,
})


return skel
